<?php

namespace App\Http\Controllers;

use App\Model\Category;
use App\Model\Link;
use App\Model\Setting;
use Illuminate\Foundation\Bus\DispatchesJobs;
use Illuminate\Routing\Controller as BaseController;
use Illuminate\Foundation\Validation\ValidatesRequests;
use Illuminate\Foundation\Auth\Access\AuthorizesRequests;
use Illuminate\Support\Facades\View;

class Controller extends BaseController
{
    use AuthorizesRequests, DispatchesJobs, ValidatesRequests;

    public function __construct()
    {
        View::share('categories', Category::getAllCategories());
        // LOGO
        $logo = Setting::where('type', Setting::TYPE_LOGO)->first();
        if ($logo->value) {
            View::share('logo', '/uploads/' . $logo->value);
        }

        $banner = Setting::where('type', Setting::TYPE_BANNER)->first();
        if ($banner->value) {
            View::share('banner', '/uploads/' . $banner->value);
        }

        // 查询系统自定义链接
        $links = Link::orderBy('sort', 'desc')
            ->orderBy('id', 'desc')->get();

        View::share('links', $links);
    }

}
